<template>
  <van-popup
    :style="{ height: '100%',backgroundColor:'#eee' }"
    position="bottom"
    v-model="show"
  >
    <van-nav-bar
      @click-left="show = false"
      @click-right="OnComplete"
      left-text="取消"
      right-text="完成"
      title="修改昵称"
    />
    <van-field
      autosize
      maxlength="7"
      placeholder="请输入昵称"
      rows="2"
      show-word-limit
      type="textarea"
      v-model="username"
    />
  </van-popup>
</template>

<script>
import { updateUserProfile } from "../../../network/user";

export default {
  name: "EditorName",
  props: ["info"],
  components: {},
  computed: {},
  data() {
    return {
      show: false,
      username: ""
    };
  },
  created() {},
  mounted() {},
  methods: {
    isShow() {
      this.show = true;
    },
    async OnComplete() {
      if (this.username.trim()) {
        const result = await updateUserProfile({
          name: this.username
        });
        if (result.message === "OK") {
          this.info.name = this.username;
          this.show = false;
          this.$toast.success("修改成功");
          this.username = "";
          return;
        }
        this.$toast.fail("修改失败");
        this.username = "";
      }else{
        this.$toast.fail("不可以为空");
        this.username = ""
      }
    }
  }
};
</script>

<style scoped lang= >
</style>